<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/INewsAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IConnectionAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/ConnectionFactory.php';

	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];

	class   MySqlNewsAccessDao implements INewsAccessDao {
  
 	 	/**
		 * Constructor
		 */
	 public function __construct () {}
	 
  
     public function createNews($news) 
	 {		 	
		$date = $news -> getDate();
		$image = $news -> getImage();
		$title = $news -> getTitle();
		$description = $news -> getDescription();
		
		 $GLOBALS['debug'] -> log($date, "DAO");
		$connection = ConnectionFactory::getMySqlConnectionAccessDao();
		$conn=$connection->openConnection();
		$query = "INSERT INTO NEWS 
		           VALUES (null,'$date','$image','$title','$description')";
	 
	 	 $GLOBALS['debug'] -> log($query, "DAO");
	 
	    $sentence=mysql_query($query,$conn);
	       if ($sentence){
			    return true;
			   }
		  return false;
	 
	 }
	 
	public function selectNews() { 
		$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
		$conn = $connection -> openConnection();		
		
		$query = "SELECT date, image, title, description
				  FROM NEWS
				  ORDER BY date DESC
				  LIMIT 10";
		
		$sentence = mysql_query($query, $conn);
			
		$conn = $connection -> closeConnection($conn);
		
		return $sentence;
	}

  
  }


?>